package com.fr.report.js;

import com.fr.base.StringUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.web.Repository;

public class EmailHyperlink extends AbstractHyperlink
{
  private String email;
  private String sentMailMethod;

  public EmailHyperlink()
  {
    this.email = "";
    this.sentMailMethod = "FR.sentEMail";
  }

  public EmailHyperlink(String paramString)
  {
    this(paramString, "");
  }

  public EmailHyperlink(String paramString1, String paramString2)
  {
    this.email = "";
    this.sentMailMethod = "FR.sentEMail";
    setEmail(paramString1);
    setTargetFrame(paramString2);
  }

  public String getEmail()
  {
    return this.email;
  }

  public void setEmail(String paramString)
  {
    this.email = paramString;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("Email")))
    {
      String str;
      if (StringUtils.isNotBlank(str = paramXMLableReader.getElementValue()))
        setEmail(str);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("JavaScript").attr("class", getClass().getName());
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Email").textNode(getEmail()).end();
    paramXMLPrintWriter.end();
  }

  public String createURL(Repository paramRepository)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    localStringBuffer.append(this.sentMailMethod).append("(\"");
    if (getEmail().toLowerCase().startsWith("mailto:"))
      localStringBuffer.append(getEmail());
    else
      localStringBuffer.append("mailto:").append(getEmail());
    localStringBuffer.append("\")");
    return localStringBuffer.toString();
  }

  public boolean equals(Object paramObject)
  {
    if (paramObject == this)
      return true;
    if (!(paramObject instanceof EmailHyperlink))
      return false;
    return ((super.equals(paramObject)) && (ComparatorUtils.equals(this.email, ((EmailHyperlink)paramObject).email)));
  }
}